//
//  XMMyMeetingViewController.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/5/23.
//

#import "XMMyMeetingViewController.h"
#import "XMMyMeetingView.h"
#import "XMNetwork+mine.h"
#import "XMPublishViewController.h"
#import "XMMeetingModel.h"

@interface XMMyMeetingViewController ()<XMMyMeetingViewDelegate>

@property (nonatomic, strong) XMMyMeetingView *myMeetingView;

@property (nonatomic, copy) NSString *stateStr;
@property (nonatomic, assign) NSInteger page;

@end

@implementation XMMyMeetingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    [self.view addSubview:self.myMeetingView];
    _page = 1;
    _stateStr = @"10";
    [self getMyMeetingListWithStatus:_stateStr];
}

- (void)getMyMeetingListWithStatus:(NSString *)statusStr {
    NSInteger orderType = 0;
    if ([statusStr isEqualToString:@"1"]) {
        orderType = 1;
    }
    else if ([statusStr isEqualToString:@"-1"]) {
        orderType = 2;
    }
    XMWeakSelf;
    [_Network getMyMeetingWithStatus:statusStr
                             deleted:@""
                              userId:_userId
                             pageNum:[NSString stringWithFormat:@"%ld", _page]
                             success:^(id  _Nonnull responseObject) {
        NSArray *meetingModelArr = [NSArray yy_modelArrayWithClass:[XMMeetingModel class] json:responseObject[@"data"]];
        [weakSelf.myMeetingView setContentWithMeetingModelArr:meetingModelArr
                                                         page:weakSelf.page
                                                    orderType:orderType userId:weakSelf.userId];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

//删除见面
- (void)meetingDeleteWithServiceId:(NSString *)serviceId {
    XMWeakSelf;
    [_Network deleteMeetingWithServiceId:serviceId
                                 success:^(id  _Nonnull responseObject) {
        [weakSelf refreshData];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

//下架见面
- (void)meetingSoldoutWithServiceId:(NSString *)serviceId {
    XMWeakSelf;
    [_Network meetingSoldOutWithServiceId:serviceId
                                  success:^(id  _Nonnull responseObject) {
        [weakSelf refreshData];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

//上架见面
- (void)meetingReputawayWithServiceId:(NSString *)serviceId {
    XMWeakSelf;
    [_Network meetingReputawayWithServiceId:serviceId
                                    success:^(id  _Nonnull responseObject) {
        [weakSelf refreshData];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}
//"coverImageUrl": "https://example.com/cover3.jpg",
#pragma mark - Delegate
- (void)refreshData {
    _page = 1;
    [self getMyMeetingListWithStatus:_stateStr];
}

- (void)loadMore {
    _page += 1;
    [self getMyMeetingListWithStatus:_stateStr];
}

- (void)stateSelect:(NSString *)stateStr {
    _stateStr = stateStr;
    _page = 1;
    [self getMyMeetingListWithStatus:stateStr];
}

//编辑
- (void)meetingEditWithServiceId:(NSString *)serviceId {
    XMPublishViewController *findVC = [[XMPublishViewController alloc] init];
    findVC.serviceId = serviceId;
    findVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:findVC animated:YES];
    XMWeakSelf;
    findVC.saveSuccessBlock = ^{
        [weakSelf refreshData];
    };
}

#pragma mark - Init
- (XMMyMeetingView *)myMeetingView {
    if (!_myMeetingView) {
        _myMeetingView = [[XMMyMeetingView alloc] initWithFrame:self.view.bounds];
        _myMeetingView.delegate = self;
    }
    return _myMeetingView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
